package com.mall.shop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.shop.entity.member.MemberReceiveAddress;
import com.mall.shop.service.MemberReceiveAddressService;
import com.mall.shop.utils.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (MemberReceiveAddress)表控制层
 *
 * @author 龙茶清欢
 * @since 2023-01-15 14:23:48
 */
@RestController
@RequestMapping("/memberReceiveAddress")
@RequiredArgsConstructor
@Tag(name = "管理", description = "管理")
public class MemberReceiveAddressController {
  
    private final MemberReceiveAddressService memberReceiveAddressService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param memberReceiveAddress 查询实体
     * @return 所有数据
     */
    @GetMapping("/findByPage")
    @Operation(description = "通过分页查询")
    public R<Object> findByPage(Page<MemberReceiveAddress> page, MemberReceiveAddress memberReceiveAddress) {
        return R.ok(memberReceiveAddressService.page(page, new QueryWrapper<>(memberReceiveAddress)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/findById/{id}")
    @Operation(description = "通过ID查询")
    public R<Object> findById(@PathVariable Long id) {
        return R.ok(memberReceiveAddressService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param memberReceiveAddress 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    @Operation(description = "新增")
    public R<Object> insert(@RequestBody MemberReceiveAddress memberReceiveAddress) {
        return R.ok(memberReceiveAddressService.save(memberReceiveAddress));
    }

    /**
     * 修改数据
     *
     * @param memberReceiveAddress 实体对象
     * @return 修改结果
     */
    @PutMapping("/update")
    @Operation(description = "更新")
    public R<Object> update(@RequestBody MemberReceiveAddress memberReceiveAddress) {
        return R.ok(memberReceiveAddressService.updateById(memberReceiveAddress));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/delete")
    @Operation(description = "删除")
    public R<Object> delete(@RequestParam("idList") List<Long> idList) {
        return R.ok(memberReceiveAddressService.removeByIds(idList));
    }
    
}

